package com.x.wx.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.x.framework.dao.BaseDao;
import com.x.wx.model.WxMenu;

/**
 * Created by Administrator on 2018/1/8.
 */
@Repository
public class WxMenuDao  extends BaseDao{

    private final static  String  selectWxMenuListSql = "SELECT T1.* FROM WX_MENU  T1 WHERE 1=1 ";
    /**
     * 查询微信用户
     * @param wxMenu
     * @return
     * @throws Exception
     */

    public List<WxMenu> selectWxMenuList(WxMenu wxMenu) throws Exception{
        StringBuilder sql = new StringBuilder(selectWxMenuListSql);
        List<Object> params = new ArrayList<Object>();
        searchCondition(sql, params, wxMenu);
        sql.append("ORDER BY MENU_SEQ ASC");
        return this.queryForList(sql.toString(), WxMenu.class, params);
    }

    /**
     * 查询条件
     * @param sql
     * @param params
     * @param wxMenu
     */
    private void searchCondition(StringBuilder sql, List<Object> params, WxMenu wxMenu) {
        if(wxMenu != null) {
            if(StringUtils.isNotEmpty(wxMenu.getMenuId())){
                sql.append("AND T1.MENU_ID = ? ");
                params.add(wxMenu.getMenuId());
            }
            if(StringUtils.isNotEmpty(wxMenu.getMenuType())){
                sql.append("AND T1.MENU_TYPE = ? ");
                params.add(wxMenu.getMenuType());
            }
            if(StringUtils.isNotEmpty(wxMenu.getMenuParentId())){
            	sql.append("AND T1.MENU_PARENT_ID = ? ");
            	params.add(wxMenu.getMenuParentId());
            }
            if(StringUtils.isNotEmpty(wxMenu.getAccountId())){
                sql.append("AND T1.ACCOUNT_ID = ? ");
                params.add(wxMenu.getAccountId());
            }
        }
    }

}
